home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c / 238 < prev    next >
Encoding:
Text File  |  1996-08-06  |  2.0 KB  |  55 lines

  1. Newsgroups: comp.lang.c,comp.std.c
  2. Path: hobbes.sco.COM!scocan!john
  3. From: john@sco.com (John R MacMillan)
  4. Subject: Re: Integral conversion e.t.c. (was: Re: Hungarian notation)
  5. Organization: SCO Canada, Inc.
  6. Date: Tue, 30 Jan 1996 20:40:29 GMT
  7. Message-ID: <DM0HFI.GEA@sco.COM>
  8. References: <30C40F77.53B5@swsbbs.com> <KANZE.96Jan29121956@slsvewt.lts.sel.alcatel.de> <4eindq$eju@solutions.solon.com> <DLzK76.88@ukpsshp1.serigate.philips.nl>
  9. Sender: news@sco.COM (News administration)
  10.  
  11. |However if having perfomed the correct incantation - if the compiler fails
  12. |to give a diagnostic required by the standard then that is a bug in the
  13. |compiler - even if it then goes on to generate useful code. The whole point
  14. |about a standard compiler is that if code compiles clean on one, it should
  15. |compile clean on all.
  16.  
  17. Unless you mean something different by ``clean'' than I do (no
  18. diagnostics), then I have to disagree, for two reasons.  One is that a
  19. compiler that conforms to the standard is not obliged to catch non-
  20. conforming programs, so a clean compile does not mean a conforming
  21. program.  The other reason is that a standard compiler is free to
  22. issue diagnostics that are not required as a quality-of-implementation
  23. matter.
  24.  
  25. Consider the following (poorly written) module:
  26.  
  27. #include <stdio.h>
  28. #include <stlib.h>
  29.  
  30. int increment(int n)
  31. {
  32.     int m;
  33.  
  34.     m = n + 1;
  35.     if (m < n) {
  36.         exit(EXIT_FAILURE);
  37.         puts("This never gets printed");
  38.     } else {
  39.         return m;
  40.     }
  41.  
  42.     puts("This never gets printed either");
  43. }
  44.  
  45. A conforming compiler may note that exit() never returns and remark
  46. about unreachable code, or it may not, and remark that control could
  47. reach the end of the function without a return, or it might compile
  48. with no diagnostics at all (in fact I've seen implementations that
  49. match all of these behaviours).  And I don't imagine anyone would
  50. expect it diagnose that the ``n + 1'' might overflow, resulting in
  51. undefined runtime behaviour but it could.
  52.  
  53. So even if it compiles clean with my compiler, I can't expect it to do
  54. so with yours, and I can't even expect that the program is conforming.
  55.